<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

App::uses('AppController', 'Controller');

/**
 * CakePHP InstagramController
 * @author Felipe
 */
Configure::write('debug', 2);

class InstagramController extends SocialAppController {

    public $client_id = '21bf2ce4f3b54955b6d0c8449fdeb408';
    public $client_secret = '2c9371840bbf44659cd0c98494cbb489';
    public $website_uri = 'http://cms.williarts.com.br/beta';
    public $redirect_uri = 'http://cms.williarts.com.br/beta/painel/social/instagram/callback';
    public $response_type = 'token';

    public function painel_index() {
        header('Location: https://api.instagram.com/oauth/authorize/?client_id=' . $this->client_id . '&redirect_uri=' . $this->redirect_uri . '&response_type=' . $this->response_type);
    }

    public function painel_callback() {
        
    }

    public function painel_autorizacao() {
        $this->loadModel('Social.Social');
        $this->Social->deleteAll(array('Social.tipo' => 'instagram'), false);
        $this->Social->save(array(
            'Social' => array(
                'chave' => $this->client_id,
                'chave_secreta' => $this->client_secret,
                'redirect_uri' => $this->redirect_uri,
                'website_url' => $this->website_uri,
                'token' => $this->request->params['pass'][0],
                'tipo' => 'instagram'
            )
        ));
        $this->redirect(array('controller' => 'sociais', 'action' => 'index'));
    }

}
